/*
 *   Copyright 2021 zzh
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

package com.aduib.boot.common.SPI;

import com.aduib.boot.common.SPI.SPIDefinition.SPIRole;
import com.aduib.boot.common.log.LOG;

/**
 * @description: SPIDefinitionBuilder
 * @author: zzh
 * @date: 2021/9/18 16:18
 */
public final class SPIDefinitionBuilder {

  /**
   * 创建SPIDefinition
   *
   * @param name
   * @param clazz
   * @param role
   * @return
   */
  public static SPIDefinition build(String name, Class<?> clazz, SPIRole role) {
    LOG.d("create SPIDefinition[name: {}, class: {}, role: {}]", name, clazz, role);
    SPIDefinition definition = null;
    switch (role) {
      case NORMAL_SPI:
        definition = new DefaultSPIDefinition(name, clazz,role);
        break;
      case INTERNAL_SPI:
        definition = new DefaultInternalSPIDefinition(name, clazz,role);
        break;
      case NORMAL_SERVICES:
        definition = new DefaultServiceDefinition(name, clazz,role);
        break;
      default:
        break;
    }
    return definition;
  }
}
